﻿using ComponentFactory.Krypton.Toolkit;
using SRB.Tg.Operate;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SRB.Tg.Cad
{
    public partial class SelectInfoForm :   KryptonForm
    {
        string _type = "pileCap";
        public SelectParameter para;

        public SelectInfoForm(string type= "pileCap")
        {
            InitializeComponent();
            para = new SelectParameter();
            _type = type;
            InitData();
        }

        private void InitData()
        {
            string tableName = "t_cap_reinforcement";
            switch(_type)
            {
                case "pileCap":
                    tableName = "t_cap_reinforcement";
                    cbScale.Text ="80";
                    break;
                case "Plinth":
                    tableName = "t_cushion_stone";
                    cbScale.Text = "20";
                    break;
                case "pile":
                    tableName = "t_pile_reinforcement";
                    cbScale.Text = "80";
                    break;
            }
            string sql = string.Format("select  id,configure_name from {0} where status=0 order by id desc", tableName);
            System.Data.DataTable dt = MySqlHelper.ExecuteDataTable(sql, CommandType.Text);
            if(dt.Rows.Count>0)
            {
                cb.DataSource = dt;
                cb.DisplayMember = "configure_name";
                cb.ValueMember = "id";
            }

        }

        private void btnConfim_Click(object sender, EventArgs e)
        {
            if(string.IsNullOrWhiteSpace(cb.Text))
            {
                MessageBox.Show("请选择配置！", "提示");
                return;
            }
            this.DialogResult = DialogResult.OK;
            para.Id = cb.SelectedValue.ToString();
            para.Name = cb.Text;
            para.Scale = int.Parse(cbScale.Text);
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }

    public class SelectParameter
    {
        /// <summary>
        /// ID
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 横桥向宽度
        /// </summary>
        public string Name { get; set; }
        public int Scale { get; set; }
    }
}
